package cn.thoughtworks.school.services;

import cn.thoughtworks.school.feign.ProgramCenterFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class ProgramCenterService {
    @Autowired
    private ProgramCenterFeign programCenterFeign;

    public Map getProgramById(Long programId) {
      HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
      String token = request.getHeader("token");
      return programCenterFeign.getProgramById(programId,token);
    }

    public Map getAssignment(String assignmentId) {
        return programCenterFeign.getAssignmentById(Long.parseLong(assignmentId));
    }

    public List getMyTutors(Long programId, Long userId) {
        return programCenterFeign.getMyTutors(programId, userId);
    }
}
